package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan int, 3)
	//len(ch)缓冲区中剩余数据的个数，cap（ch）缓冲区大小，或者容量
	fmt.Printf("%T\n",ch)
	fmt.Printf("len(ch)=%d,cap(ch)=%d\n", len(ch), cap(ch))

	go func (){
		defer fmt.Println("zi结束")
		for i:=0;i<3 ;i++ {
			ch<-i
			fmt.Printf("i=%d,len(ch)=%d,cap(ch)=%d\n", i,len(ch), cap(ch))

		}
	}()
	time.Sleep(time.Second)
	/*for i:=0;i<3;i++{
		num:=<-ch
		fmt.Println(num)

	}*/
	//组合判断拿通道里的数据
	/*for {
		if num,ok:=<-ch;ok{
			fmt.Println(num)
		}else{
			break
		}
	}
	*/
	//遍历通道
	for num:=range ch {
		fmt.Println(num)
	}
}